<template>
  <s-layout id="layout" :title="'查看日周月报'" navbar="normal" leftIconColor="#333" :autoBack="false"
    :bgColor="state.bgColor" :tabbarshow='false' :titleStyle="{ color: '#333', fontSize: '32rpx' }">
    <view class="call_on list_box" :style="{ paddingTop: (safeAreaInsets?.top + 44) + 'px' }">
      <view class="menu">
        <up-tabs :list="state.menulist" @click="menulistclick" :current="state.currentTab"></up-tabs>
      </view>
      <scroll-view scroll-y class="comprehensive" v-if="list.length" show-scrollbar="true"
        :refresher-enabled="isOpenRefresh" :refresher-triggered="triggered" :refresher-threshold="100"
        refresher-background="white" @refresherpulling="onPulling" @refresherrefresh="onRefresh"
        @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="onScroll">
        <view class="item_wrap">
          <view class="item" v-for="(item, index) in list" :key="index">
            <view class="item_left">
              <view class="data">{{ item.date }}</view>
            </view>
            <view class="item_right" v-if="group_id != 3 && group_id != 6" @click="lookStaffDetail(item)">
              <text :class="item.is_sub == true ? 'name' : 'yellow'">{{ item.is_sub == true ? '已提交' : '未提交' }}</text>
              <u-icon v-if="item.is_sub == true" size="10" name="arrow-right" color="#0038F7"></u-icon>
            </view>
            <view class="item_right" v-else @click="lookStaffList(item)">
              <text class="name">{{ item.sub_total }}人提交</text>
              <u-icon size="10" name="arrow-right" color="#0038F7"></u-icon>
            </view>

          </view>
        </view>
      </scroll-view>

      <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无内容"
        marginTop="50%"></u-empty>
    </view>

  </s-layout>
</template>

<script setup>
import sheep from '@/sheep';
import { onLoad } from "@dcloudio/uni-app";
import { ref, reactive, computed } from 'vue';
const userStore = sheep.$store('user');
const { safeAreaInsets } = uni.getSystemInfoSync()
const state = reactive({
  bgColor: '#fff',
  menulist: [
    { name: '日报', value: '0' },
    { name: '周报', value: '1' },
    { name: '月报', value: '2' },
  ],
  currentTab: 0
})
const list = ref([])
const group_id = ref()
const user_id = ref()
// const listpagenumber = ref(1)
onLoad((options) => {
  getRecordList()
  group_id.value = userStore.userInfo.group_id
  user_id.value = userStore.userInfo.id

})
//点击切换菜单  
const menulistclick = (e) => {
  list.value = [];
  state.currentTab = e.value;
  // listpagenumber.value = 1;
  getRecordList()
}
const type = ref()
//查看员工详情
const lookStaffDetail = (e) => {
  if (e.is_sub == false) {
    sheep.$helper.toast('暂无提交，还不能查看哦');
    return;
  } else {
    if (state.currentTab == 0) {
      type.value = 1
    } else if (state.currentTab == 1) {
      type.value = 2
    } else if (state.currentTab == 2) {
      type.value = 3
    }
    sheep.$router.go('/subpackage/staff/workbench/daily_record/final_report_detail', {
      date: e.date,
      type: type.value,
      user_id: user_id.value
    });
  }

}
// 查看员工列表
const lookStaffList = (e) => {
  if (e.is_sub == false) {
    sheep.$helper.toast('暂无人提交，还不能查看哦');
    return;
  } else {
    if (state.currentTab == 0) {
      type.value = 1
    } else if (state.currentTab == 1) {
      type.value = 2
    } else if (state.currentTab == 2) {
      type.value = 3
    }
    sheep.$router.go('/subpackage/staff/workbench/daily_record/final_report_staff', {
      date: e.date,
      type: type.value,
      // user_id:user_id.value
    });
  }
}

//数据请求
const getRecordList = () => {
  if (state.currentTab == '0') {
    sheep.$api.report.getDailyRecordList().then((res) => {
      list.value = res?.data
    });
  }
  if (state.currentTab == '1') {
    sheep.$api.report.getWeekList().then((res) => {
      list.value = res?.data
    });
  }
  if (state.currentTab == '2') {
    sheep.$api.report.getMonthRecord().then((res) => {
      list.value = res?.data
    });
  }



}
// 页面下拉刷新
const freshing = ref(false)
const triggered = ref(false)
const isOpenRefresh = ref(true)  // 是否开启下拉
// 自定义下拉刷新控件被下拉
const onPulling = (e) => {
  if (e.detail.deltaY < 0) return  // 防止上滑页面也触发下拉
  triggered.value = true;
}
// 自定义下拉刷新被触发
const onRefresh = () => {
  if (freshing.value) return;
  freshing.value = true;
  setTimeout(() => {
    // listpagenumber.value = 1;
    list.value = []
    triggered.value = false;
    freshing.value = false;
    getRecordList();
  }, 500);
}
// 自定义下拉刷新被复位
const onRestore = () => {
  triggered.value = 'restore'; // 需要重置
  // console.log("onRestore");
}
// 自定义下拉刷新被中止
const onAbort = () => {
  // console.log("onAbort");
}


</script>

<style lang="scss" scoped>
// 滚动
.comprehensive {
  width: calc(100% - 40rpx);
  background-color: rgba(0, 0, 0, 0);
  margin: 0 20rpx;
  height: 81vh;
}

//列表
.call_on {
  width: 100%;
  height: 89vh;

  .list_box {
    width: 100%;
    height: auto;
  }

}

.loading-text {
  text-align: center;
  font-size: $uni-font-size-base;
  color: #666;
  padding: 20rpx 0 50rpx;
}

// 列表内容
.item_wrap {
  border-radius: 18rpx;
  margin-top: 20rpx;
  padding: 20rpx 0;
  background: $uni-bg-color;

  .item {
    margin: 20rpx;
    border-radius: 16rpx;
    width: calc(100% - 40rpx);
    background-color: #F9FAFF;
    box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.05);
    display: flex;

    align-items: center;

    .item_left {
      width: 75%;
      padding: 25rpx 0 16rpx 30rpx;

      flex-direction: column;
      font-family: PingFangSC;
      color: $uni-text-color;

    }

    .item_right {
      padding-right: 30rpx;
      font-family: PingFangSC;

      font-weight: 400;
      font-size: 22rpx;
      display: flex;

      .name {
        margin-right: 6rpx;
        color: $uni-color-primary;
      }

      .yellow {
        color: #F77500;
        margin-right: 6rpx;
      }
    }
  }
}

.menu {
  width: 100%;
  height: 98rpx;
  background: $uni-bg-color;

  :deep(.u-tabs__wrapper__nav__item) {
    width: 28%;
  }

  :deep(.u-tabs__wrapper__nav__line) {
    width: 30rpx !important;
    height: 8rpx !important;
    border-radius: 4rpx !important;
    background: linear-gradient(90deg, rgba(0, 56, 247, 1) 0%, rgba(77, 139, 255, 1) 100%) !important;
  }
}
</style>